package server;

import java.net.UnknownHostException;
import java.rmi.*;
import java.rmi.registry.*;

import common.ServerInterface;

public class Foop1GameServer {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		try {
			System.out.println("export RMI service on " + 
					java.net.InetAddress.getLocalHost() + ":" +
					Registry.REGISTRY_PORT
					);
			
			ServerInterface stub = (ServerInterface) new ServerInterfaceImpl();
//					UnicastRemoteObject.exportObject(new ServerInterfaceImpl(), 0);
			
			Registry r = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
			System.out.println("Server : Registry wurde erzeugt.");

			r.bind(ServerInterface.RMIName, stub);
			
			// TODO: implement a wait handler to unbind objects...
			
		} catch (RemoteException e) {
			System.err.println("could not create registry or bind server interface");
			System.err.println(e.getLocalizedMessage());
			System.exit(1);
			
		} catch (AlreadyBoundException e) {
			System.err.println("registry port already in use. server already started?");
			System.err.println(e.getLocalizedMessage());
			System.exit(1);
			
		} catch (UnknownHostException e) {
			System.err.println("UnknownHostException");
			System.err.println(e.getLocalizedMessage());
			System.exit(1);
			
		}
		
	}

}
